package taskit.datastructures;

import java.io.Serializable;
import java.util.LinkedList;

import org.codehaus.jackson.annotate.JsonTypeInfo;

//@author A0105301E
@JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.PROPERTY, property="@class")
public class Schedule extends Deadline implements Serializable {
	
	private static final String ERR_START_LATER_THAN_END = "Error: The start date is later than the end date.";
	private static final String ERR_CANNOT_CREATE_TASK_IN_PAST = "You may not create a task that falls before now.";
	
	private Date startDate;
	
	public Schedule(String name, Date start, Date end) {
		super(name, end);
		this.startDate = start;		
	}
	
	public Schedule(String name, Date start, Date end, LinkedList<String> tags) {
		super(name, end, tags);
		this.startDate = start;		
	}
	
	public Schedule() {

	}
	
	public static Schedule createSchedule(String name, Date start, Date end) throws Exception {	
		if (start.compareTo(end) >= 0) {
			throw new Exception(ERR_START_LATER_THAN_END);
		}
		if (end.compareTo(Date.currentDate()) < 0) {
			throw new Exception(
					);
		}
		return new Schedule(name, start, end);
	}
	
	public static Schedule createSchedule(String name, Date start, Date end, LinkedList<String> tags) throws Exception {
		if (start.compareTo(end) >= 0) {
			throw new Exception(ERR_START_LATER_THAN_END);
		}
		if (end.compareTo(Date.currentDate()) < 0) {
			throw new Exception(
					ERR_CANNOT_CREATE_TASK_IN_PAST);
		}
		return new Schedule(name, start, end, tags);
	}
	
	public Date getStartDate() {
		return startDate;
	}
	
	public void setStartDate(Date start) {
		startDate = start;
	}	
}
